package com.example.myshop.service;

import com.example.myshop.entity.UserPurse;
import com.example.myshop.service.ex.ServiceException;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.stereotype.Service;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.List;

@SpringBootTest
@RunWith(SpringRunner.class)
@Service
public class userpurseservicetest {
    @Autowired UserPurseService userPurseService;

    @Test
    public void test1(){
        UserPurse user=new UserPurse();
        user.setUid(15L);
        user.setUsername("root");
        user.setPurse(87120);
        user.setAddAmount(80);
        user.setSubAmount(0);
//        user.setModifiedUser("root");
//        user.setModifiedTime(new Date());
        userPurseService.insert(user);
        try {
            System.out.println("成功");
        } catch (ServiceException e) {
            //获取类的对象，再获取类的名称
            System.out.println(e.getClass().getSimpleName());
            //获取异常具体描述信息
            System.out.println(e.getMessage());
        }
    }
    @Test
    public void inserts(){
        UserPurse user=new UserPurse();
        user.setUid(34L);
        user.setUsername("root");
        user.setPurse(5438);
        user.setAddAmount(0);
        user.setSubAmount(100);
//        user.setModifiedUser("root");
//        user.setModifiedTime(new Date());
        userPurseService.inserts(user);
        try {
            System.out.println("成功");
        } catch (ServiceException e) {
            //获取类的对象，再获取类的名称
            System.out.println(e.getClass().getSimpleName());
            //获取异常具体描述信息
            System.out.println(e.getMessage());
        }
    }

    @Test
    public void getByUid(){
        List<UserPurse> result = userPurseService.getByUid(15L);
        System.err.println(result);
    }
}
